<?php
/**
 * Date: 2024.8
 * Author: kahn
 * 慢日志输出
 */

class BenchmarkPlugin extends Yaf_Plugin_Abstract {
	public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
        $start = microtime(true);
        register_shutdown_function(
            function () use ($request, $start) {
                $time = round(microtime(true) - (float)$start, 5);
                if ($time > 1)
                {
                    \Log::info('benchmark ' . $request->getRequestUri() . ':' . $time . ':' . (memory_get_usage(true) / 1024) . 'kb');
                }
            }
        );
	}
}
